package com.xxx.service.impl;

import com.xxx.dao.OrderProduceDao;
import com.xxx.entity.MPage;
import com.xxx.entity.OrderProduce;
import com.xxx.dao.OrderProduceDao;
import com.xxx.entity.dto.OrderProduceDto;
import com.xxx.entity.query.OrderProduceQuery;
import com.xxx.entity.query.OrderProduceQuery;
import com.xxx.service.IOrderProduceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xxx
 * @since 2024-11-24
 */
@Service
public class OrderProduceServiceImpl extends ServiceImpl<OrderProduceDao, OrderProduce> implements IOrderProduceService {

    @Autowired
    private OrderProduceDao orderProduceDao;
    @Override
    public MPage selectByPage(Integer current, Integer size) {
        int total = orderProduceDao.selectCount(null);
        List<OrderProduceDto> list = orderProduceDao.selectByPage((current-1)*size,size);
        MPage page = MPage.builder()
                .current(current)
                .size(size)
                .total(total)
                .pages(total/size+total%size>0?1:0)
                .records(list)
                .build();
        return page;
    }

    @Override
    public MPage selectByCondition(OrderProduceQuery orderProduceQuery) {
        int current = orderProduceQuery.getCurrent();
        int size = orderProduceQuery.getSize();
        orderProduceQuery.setCurrent((current-1)*size);
        List<OrderProduceDto> list = orderProduceDao.selectByCondition(orderProduceQuery);
        int total = list.size();
        MPage page = MPage.builder()
                .current(current)
                .size(size)
                .total(total)
                .pages(total/size+total%size>0?1:0)
                .records(list)
                .build();
        return page;
    }
}
